package zzcltw.com.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import zzcltw.com.mapper.PersonMapper;
import zzcltw.com.object.Person;
import zzcltw.com.service.IPersonService;
import zzcltw.com.service.common.impl.BaseServiceImpl;
import zzcltw.com.util.StringUtil;

@Service("persionService")
public class PersionServiceImpl extends BaseServiceImpl implements IPersonService{
	@Autowired
    private PersonMapper personMapper;//这里会报错，但是并不会影响
	/**
	 * 
	 * @Title queryPersonList
	 * @Description: 人员信息列表查询
	 * @param: @param person	
	 * @return void
	 * @throws
	 * @author zzx
	 * @Date 2018年8月15日   上午11:33:17
	 */
	public Map<String, Object> queryPersonList(Map<String,String> map){
		List<Map<String,String>> list = personMapper.queryPersonList(map);
		int count = personMapper.queryPersonListCount(map);
		Map<String,Object> bean = new HashMap<>();
		bean.put("total", Integer.toString(count));
		Map<String,Object> map1 = new HashMap<>();
		map1.put("beans", list);
		map1.put("bean", bean);
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", "");
    	map1.put("busiCode", ""); 
		return map1;
	}
	/**
	 * 
	 * @Title queryPersonDtlById
	 * @Description: 人员信息详情
	 * @param: @param person	
	 * @return void
	 * @throws
	 * @author zzx
	 * @Date 2018年8月23日   上午11:33:17
	 */
	public Map<String, Object> queryPersonDtlById(Person person){
		person.setValidStsCd("1");
		Map<String,String> bean = personMapper.queryPersonDtlById(person);
		Map<String,Object> map1 = new HashMap<>();
		map1.put("beans", null);
		map1.put("bean", bean);
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", "");
    	map1.put("busiCode", ""); 
		return map1;
	}
	/**
	 * 
	 * @Title savePersonInfo
	 * @Description: 新增人员信息
	 * @param: @param person
	 * @return void
	 * @throws Exception
	 * @author zzx
	 * @Date 2018年8月15日   上午11:33:17
	 */
	public Map<String, Object> savePersonInfo(Person person) throws Exception{
		String personId = getSequence("t_pt_personnel");		
		person.setPersonId(personId);
		person.setValidStsCd("1");
		int flag = personMapper.savePersonInfo(person);		
    	Map<String,Object> bean = new HashMap<>();
    	if(flag != 1){
    		bean.put("rtnCd", "9999");
    	}else {
    		bean.put("rtnCd", "00");
    	}
    	Map<String,Object> map1 = new HashMap<>();
		map1.put("bean", bean);
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", "");
    	map1.put("busiCode", "");		
    	return map1;
	}
	/**
	 * 
	 * @Title updatePersonInfo
	 * @Description: 编辑人员信息
	 * @param: @param person
	 * @return void
	 * @throws Exception
	 * @author zzx
	 * @Date 2018年8月15日   上午11:33:17
	 */
    public Map<String, Object> updatePersonInfo(Person person)throws Exception{
    	person.setValidStsCd("1");
    	int flag = personMapper.updatePersonInfo(person);
    	/*Map<String,String> delMap = new HashMap<>();
    	delMap.put("objId", person.getPersonId());
    	personMapper.delPersonInfoFile(delMap);
    	String filePaths = person.getFilePaths();
    	String personId = person.getPersonId();
    	String crtUserId = person.getCrtUserId();
    	if(StringUtil.isNotEmpty(filePaths)){
    		String arr[] = filePaths.split(",");
    		for(int i=0;i<arr.length;i++){
    			Map<String,String> map = new HashMap<>();
    			String fileId = getSequence("t_pt_person_file");	
    			map.put("fileId", fileId);
    			map.put("personId", personId);
    			map.put("fileTypeCd", "01");
    			map.put("fielNm", arr[i]);
    			map.put("filePath", arr[i]);
    			map.put("crtUserId", crtUserId);
    			map.put("validStsCd", "1");
    			personMapper.savePersonInfoFile(map);
    		}
    	}*/
    	Map<String,Object> bean = new HashMap<>();
    	if(flag != 1){
    		bean.put("rtnCd", "9999");
    	}else {
    		bean.put("rtnCd", "00");
    	}
    	Map<String,Object> map1 = new HashMap<>();
		map1.put("bean", bean);
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", "");
    	map1.put("busiCode", "");		
    	return map1;
    }
    /**
	 * 
	 * @Title delPersonInfo
	 * @Description: 删除人员信息
	 * @param: @param person
	 * @return void
	 * @throws Exception
	 * @author zzx
	 * @Date 2018年8月15日   上午11:33:17
	 */
    public Map<String, Object> delPersonInfo(Person person)throws Exception{
    	int flag = personMapper.delPersonInfo(person);
    	//Map<String,String> delMap = new HashMap<>();
    	//delMap.put("objId", person.getPersonId());
    	//personMapper.delPersonInfoFile(delMap);
    	Map<String,Object> bean = new HashMap<>();
    	if(flag != 1){
    		bean.put("rtnCd", "9999");
    	}else {
    		bean.put("rtnCd", "00");
    	}
    	Map<String,Object> map1 = new HashMap<>();
		map1.put("bean", bean);
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", "");
    	map1.put("busiCode", "");		
    	return map1;
    }
}
